package org.jsola.hr.task;

import lombok.extern.slf4j.Slf4j;
import org.jsola.hr.dao.ICompanyDAO;
import org.jsola.hr.entity.TaskDO;
import org.jsola.hr.provider.IMessageProviderService;
import org.jsola.hr.service.IMemoInfoService;
import org.jsola.hr.service.ISalaryBillSendService;
import org.jsola.hr.service.ITaskService;
import org.jsola.user.core.TokenUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 备忘录提醒，提前发送系统通知定时任务
 *
 * @author
 */
@Slf4j
@Component
public class HrMemoRemindTask {


    @Autowired
    private ICompanyDAO companyDAO;

    @Autowired
    private IMessageProviderService messageProviderService;

    @Autowired
    private ITaskService taskService;

    @Autowired
    private ISalaryBillSendService salaryBillSendService;

    @Autowired
    private IMemoInfoService memoInfoService;


    /**
     * 备忘录提醒发送消息通知
     * @param taskId 任务ID
     * @return
     */
    public void runTask(String taskId, TokenUser tokenUser) {
        TaskDO task = taskService.selectDOById(taskId, "");
        if (Objects.nonNull(taskId)) {
            log.info("开始执行定时任务-----------:{}", task);

            // 备忘录提醒发送消息通知
            memoInfoService.memoRemindNotice(task.getSubjectId(), tokenUser);

            // 任务置为已完成
            taskService.taskRunEnd(task.getId(), tokenUser);
            log.info("定时任务task:{}执行结束", task.getId());
        }
    }


}
